/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.insert;
import hibernate.HibernateUtil;
import hibernate.dao.Venda;
import java.util.Date;
import org.hibernate.Session;

/**
 *
 * @author Ricardo
 */
public class VendaController {
    
    private VendaListener VendaListener = null;

    public VendaController() {
        this(null);
    }

    public VendaController(VendaListener VendaListener) {
        VendaListener = VendaListener;
    }
    
    public void NovaVenda(String Valor , String FormaPag,Integer Codigo){
       try{
       Venda v1 = new Venda();
       
       v1.setVenValor(Valor);
       v1.setVenFormapag(FormaPag);
       v1.setVenCodigo(Codigo);
       v1.setVenData(new Date(System.currentTimeMillis()));
     
       Session a = HibernateUtil.getSessionFactory().getCurrentSession();
       a.beginTransaction();
       a.save(v1);
       a.getTransaction().commit();
       
        } catch (Exception e) {
            VendaListener.onVendaError(e.getMessage());
        }
    }

    public void setVendaListener(VendaListener pVendaListener) {
        VendaListener = VendaListener;
    }
}

